package com.test.ioc;
//启动类扫描路径
import com.test.ioc.controller.HelloController;
import com.test.ioc.model.UserInfo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

@ComponentScan("com.test.ioc")//自定义路径
@SpringBootApplication
public class IocDemoApplication {

	public static void main(String[] args) {
		ApplicationContext context = SpringApplication.run(IocDemoApplication.class, args);
		//根据类型获取
		HelloController bean = context.getBean(HelloController.class);
		bean.sayHello();
		System.out.println(bean);
		//根据bean名称获取
		HelloController helloController = (HelloController) context.getBean("helloController");
		helloController.sayHello();
		System.out.println(helloController);
		//根据名称和类型获取
		HelloController helloController1 = context.getBean("helloController", HelloController.class);
		helloController1.sayHello();
		System.out.println(helloController1);
		//拿到的是同一个地址
//		UserInfo beanConfig = context.getBean(UserInfo.class);Bean不是唯一的UserInfo对象
		UserInfo beanConfig = (UserInfo) context.getBean("userInfo");
		UserInfo beanConfig2 = (UserInfo) context.getBean("userInfo2");




		System.out.println(beanConfig);
		System.out.println(beanConfig2);


	}

}
